package com.auto.base.ui

import android.widget.Toast
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.LocalContext
import androidx.navigation.NavHostController
import kotlinx.coroutines.flow.Flow

/**
 * Created by YuanWei1 on 2025/6/18.
 *
 * Description:
 */
@Composable
fun HandleUiEvent(
    viewModel: BaseViewModel,
    navController: NavHostController
) {
    val context = LocalContext.current
    LaunchedEffect(Unit) {
        viewModel.uiEvent.collect { event ->
            when (event) {
                is UiEvent.Toast -> Toast.makeText(context, event.message, Toast.LENGTH_SHORT).show()
                is UiEvent.NavigateTo -> navController.navigate(event.route)
                UiEvent.NavigateBack -> navController.popBackStack()
            }
        }
    }
}